{% extends "base.html" %}

{% block title %}{{ design.title }} - {{ super() }}{% endblock %}

{% block content %}
<div class="container">
    <nav aria-label="breadcrumb" class="mt-3">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{{ url_for('design.index') }}">设计案例</a></li>
            <li class="breadcrumb-item active">{{ design.title }}</li>
        </ol>
    </nav>

    <div class="card">
        <div class="card-body">
            <h1 class="card-title">{{ design.title }}</h1>
            <div class="d-flex justify-content-between align-items-center mb-4">
                <div class="text-muted">
                    <span><i class="fas fa-user"></i> {{ design.user.username }}</span>
                    <span class="ms-3"><i class="fas fa-calendar"></i> {{ design.created_at.strftime('%Y-%m-%d') }}</span>
                    <span class="ms-3"><i class="fas fa-folder"></i> {{ design.category }}</span>
                </div>
                <div>
                    <span class="me-3"><i class="fas fa-eye"></i> {{ design.views }}</span>
                    <span><i class="fas fa-heart"></i> {{ design.likes }}</span>
                </div>
            </div>

            {% if design.cover_image %}
            <img src="{{ design.cover_image }}" class="img-fluid rounded mb-4" alt="{{ design.title }}">
            {% endif %}

            <div class="mb-4">
                <h5>项目简介</h5>
                <p>{{ design.description }}</p>
            </div>

            <div class="mb-4">
                <h5>详细内容</h5>
                {{ design.content|safe }}
            </div>

            {% if design.images %}
            <div class="mb-4">
                <h5>项目图片</h5>
                <div class="row g-4">
                    {% for image in design.images.split(',') %}
                    <div class="col-md-4">
                        <img src="{{ image }}" class="img-fluid rounded" alt="项目图片">
                    </div>
                    {% endfor %}
                </div>
            </div>
            {% endif %}

            {% if design.tags %}
            <div class="mb-4">
                <h5>标签</h5>
                {% for tag in design.tags.split(',') %}
                <span class="badge bg-secondary me-2">{{ tag }}</span>
                {% endfor %}
            </div>
            {% endif %}
        </div>

        {% if current_user.is_authenticated and current_user.id == design.user_id %}
        <div class="card-footer">
            <a href="{{ url_for('design.edit', id=design.id) }}" class="btn btn-primary">编辑</a>
            <button type="button" class="btn btn-danger" onclick="deleteDesign()">删除</button>
        </div>
        {% endif %}
    </div>
</div>

{% if current_user.is_authenticated and current_user.id == design.user_id %}
<form id="delete-form" action="{{ url_for('design.delete', id=design.id) }}" method="post" style="display: none;">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
</form>

<script>
function deleteDesign() {
    if (confirm('确定要删除这个设计案例吗？此操作不可恢复。')) {
        document.getElementById('delete-form').submit();
    }
}
</script>
{% endif %}
{% endblock %} 